const MyPromise = require('./answer-04');

function p1() {
  return new MyPromise((resolve, reject) => {
    setTimeout(() => {
      resolve('p1');
    }, 5000);
  });
}

function p2() {
  return new MyPromise((resolve, reject) => {
    reject('失败');
    // resolve('p2');
  });
}

//测试MyPromise的alll方法
MyPromise.all(['a', 'b', p1(), p2(), 'c']).then(res => console.log('---all方法---', res));

//测试MyPromise的resolve方法,传入普通值
MyPromise.resolve('hello lagou').then(res => console.log('---resolve方法,普通值---', res));
//测试MyPromise的resolve方法,传入promise对象
MyPromise.resolve(p1()).then(res => console.log('---resolve方法，promise对象---', res));

//测试MyPromise的finally方法,传入回调函数
p2().finally(() => {
  console.log('finally');
  return p1()
}).then(value => {
  console.log(value);
}, reason => {
  console.log(reason);
});

//测试MyPromise的catch方法
p2()
  .then(value => console.log(value))
  .catch(reason => console.log('---catch方法---', reason))